package com.da.javatest.thread.juc.locksupport;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @author chenlida
 * @date 2020/7/11 20:23
 *
 * 1.调用LockSupport.unpark方法
 *
 * 2.调用等待线程的 interrupt()方法，给等待的线程发送中断信号，可以唤醒线程
 *
 * 3种让线程等待和唤醒的方法:
 * 方式1：Object中的wait、notify、notifyAll方法
 * 方式2：juc中Condition接口提供的await、signal、signalAll方法
 * 方式3：juc中的LockSupport提供的park、unpark方法
 */
public class LockSupport4 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            System.out.println(Thread.currentThread() + " start!");
            System.out.println("park前的中断标志位：" + Thread.currentThread().isInterrupted());
            LockSupport.park();
            System.out.println("park后的中断标志位：" + Thread.currentThread().isInterrupted());
            System.out.println(Thread.currentThread() + " end!");
        });
        thread.start();
        TimeUnit.SECONDS.sleep(3);
        thread.interrupt();
    }
}
